package com.jit.app;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import androidx.viewpager.widget.ViewPager;

import com.bumptech.glide.Glide;
import com.google.android.material.tabs.TabLayout;
import com.jit.app.adapter.AppDetailPagerAdapter;
import com.jit.app.model.Constants;

import java.util.Map;

public class AppDetailActivity extends AppCompatActivity {

    TabLayout tabs;

    ViewPager containerViewPager;

    Handler handler;

    ImageView logPicImageView;
    TextView softwareNameTextView;
    TextView downloadsTextView;
    TextView scoreTextView;

    public Map appInfo;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.setContentView(R.layout.activity_appdetail);
        MainActivity.setAndroidNativeLightStatusBar(this, true);

        appInfo = (Map) getIntent().getSerializableExtra("appInfo");

        Toolbar toolbar = findViewById(R.id.toolbar);
        toolbar.setTitle("详情");
        this.setSupportActionBar(toolbar);
        this.getSupportActionBar().setHomeButtonEnabled(true);
        this.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        initView();

    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch(item.getItemId()){
            case android.R.id.home:
                finish();
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    public void initView(){
        logPicImageView = findViewById(R.id.iv_pic);
        Glide.with(this).load(Constants.HOST.FILE_HOST+(String)appInfo.get("logoPicPath")).into(logPicImageView);
        softwareNameTextView = findViewById(R.id.tv_softwareName);
        softwareNameTextView.setText((String) appInfo.get("softwareName"));
        downloadsTextView = findViewById(R.id.tv_downloads);
        downloadsTextView.setText(appInfo.get("downloads")+"次下载");
        scoreTextView = findViewById(R.id.tv_score);
        scoreTextView.setText(appInfo.get("score")+"分");

        tabs = findViewById(R.id.tl_tabs);
        containerViewPager = findViewById(R.id.vp_container);

        containerViewPager.setAdapter(new AppDetailPagerAdapter(this.getSupportFragmentManager()));
        //TabLayout绑定ViewPager
        tabs.setupWithViewPager(containerViewPager);

    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
    }
}
